home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume19 / fbm / part06 < prev    next >
Encoding:
Internet Message Format  |  1989-06-08  |  50.8 KB

  1. Subject:  v19i052:  FBM, image manipulation library, Part06/08
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Michael.Mauldin@NL.CS.CMU.EDU
  7. Posting-number: Volume 19, Issue 52
  8. Archive-name: fbm/part06
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 6 (of 8)."
  17. # Contents:  Makefile flgifc.c flpcx.c fltga.c
  18. # Wrapped by rsalz@fig.bbn.com on Fri Jun  9 08:38:28 1989
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'Makefile'\"
  22. else
  23. echo shar: Extracting \"'Makefile'\" \(13166 characters\)
  24. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  25. X################################################################
  26. X# Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  27. X# use this file in whole or in part provided that you do not sell it
  28. X# for profit and that this copyright notice is retained unchanged.
  29. X#
  30. X#    Makefile for FBM pixmap manipulation routines
  31. X#
  32. X# HISTORY
  33. X# 20-May-89  Michael Mauldin (mlm) at Carnegie Mellon University
  34. X#    Beta relase (version 0.94) (Amiga HAM mode, bug fixes)
  35. X#
  36. X# 03-May-89  Michael Mauldin (mlm) at Carnegie Mellon University
  37. X#    Beta relase (version 0.93) (bug fixes)
  38. X#
  39. X# 30-Apr-89  Michael Mauldin (mlm) at Carnegie Mellon University
  40. X#    Beta relase (version 0.92) (color PS files, bug fixes)
  41. X#
  42. X# 06-Apr-89  Michael Mauldin (mlm) at Carnegie Mellon University
  43. X#    Added qrt2fbm, tga2fbm, fbm2tga, pic2fbm to Makefile
  44. X#    User contributed software.
  45. X#
  46. X# 16-Feb-89  Michael Mauldin (mlm) at Carnegie Mellon University
  47. X#    Alpha release (version 0.8)
  48. X#
  49. X# 18-Nov-88  Gary W. Sherwin (sherwin) at Westinghouse R&D
  50. X#       added bedge and bclean libraries and instructions.
  51. X#
  52. X# 12-Nov-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  53. X#    Created this makefile, broke libfbm into separate files
  54. X#    for compilation.
  55. X#
  56. X# Notes: "make all" will compile all of the programs.  "make install"
  57. X#     will compile all programs and place the executables in the
  58. X#     BIN directory and the manual entries in the MAN directory.
  59. X#
  60. X#     For most people, linking the executables to the bin directory
  61. X#     is fine.  But if your local software is on a different filesystem,
  62. X#     you should change the value of the INSTALL variable to either
  63. X#     "cp" or "mv".
  64. X#
  65. X#     On some systems that keep software in /usr/local, the
  66. X#     required extension on manual entries is "l" (ell).  For
  67. X#     these systems, change the MANEXT variable.
  68. X#
  69. X################################################################
  70. X
  71. XINSTALL= ln
  72. XBIN= /usr/mlm/bin/
  73. XMAN= /usr/mlm/man/
  74. XFTP= /usr/mlm/ftp/
  75. XMANEXT= 1
  76. XDBG= -g
  77. XLIB= -L. -lfbm
  78. XVER= 094
  79. XVERSTR= "FBM Library 0.94, Beta release"
  80. X
  81. XEXES= clr2gray fbcat fbclean fbedge fbext fbhalf fbhist fbinfo \
  82. X      fbm2pod fbmask fbnorm fbps fbquant fbrot fbsample fbsharp \
  83. X      gray2clr idiff pbm2ps pbmtitle raw2fbm qrt2fbm pic2fbm tga2fbm \
  84. X      fbm2tga unmap udiff fbham
  85. X
  86. XBINS= $(BIN)clr2gray $(BIN)fbcat $(BIN)fbclean $(BIN)fbedge \
  87. X      $(BIN)fbext $(BIN)fbhalf $(BIN)fbhist $(BIN)fbinfo \
  88. X      $(BIN)fbm2pod $(BIN)fbmask $(BIN)fbnorm $(BIN)fbps \
  89. X      $(BIN)fbquant $(BIN)fbrot $(BIN)fbsample $(BIN)fbsharp \
  90. X      $(BIN)gray2clr $(BIN)idiff $(BIN)pbm2ps $(BIN)pbmtitle \
  91. X      $(BIN)raw2fbm $(BIN)qrt2fbm $(BIN)pic2fbm $(BIN)tga2fbm \
  92. X      $(BIN)fbm2tga $(BIN)unmap $(BIN)udiff $(BIN)fbham
  93. X
  94. XLIBO= flalfb.o flblue.o flbyte.o flcavg.o flclr.o fledge.o flextr.o flface.o \
  95. X      flflyd.o flgifc.o flgife.o flgifr.o flgifw.o fliff.o flklnr.o flpbm.o \
  96. X      flpcx.o flrdfb.o flread.o flrot.o flshrp.o flsun.o flthre.o flwrfb.o \
  97. X      flpic.o fltga.o
  98. X
  99. XSRCS= fbext.c fbrot.c fbhist.c fbinfo.c fbmask.c fbnorm.c fbps.c fbsharp.c \
  100. X      fbedge.c fbclean.c clr2gray.c fbcat.c fbhalf.c fbm2pod.c fbquant.c \
  101. X      gray2clr.c idiff.c fbsample.c pbm2ps.c pbmtitle.c raw2fbm.c \
  102. X      fbm2tga.c tga2fbm.c pic2fbm.c qrt2fbm.c fbham.c \
  103. X      flalfb.c flblue.c flcavg.c flclr.c flextr.c flface.c flrot.c flflyd.c \
  104. X      flpbm.c flrdfb.c flread.c flshrp.c flsun.c flthre.c flwrfb.c flgifr.c \
  105. X      flgifw.c flgifc.c flgife.c flpcx.c fliff.c fledge.c flklnr.c flbyte.c \
  106. X      flpic.c fltga.c
  107. X
  108. XDOCS= clr2gray.1 fbcat.1 fbclean.1 fbedge.1 fbext.1 fbhalf.1 fbhist.1 \
  109. X      fbinfo.1 fbm.1 fbm2pod.1 fbmask.1 fbnorm.1 fbps.1 fbquant.1 fbrot.1 \
  110. X      fbsample.1 fbsharp.1 gray2clr.1 idiff.1 pbm2ps.1 pbmtitle.1 raw2fbm.1 \
  111. X      qrt2fbm.1 fbham.1
  112. X
  113. XMANS= $(MAN)clr2gray.$(MANEXT) $(MAN)fbcat.$(MANEXT) $(MAN)fbclean.$(MANEXT) \
  114. X      $(MAN)fbedge.$(MANEXT) $(MAN)fbext.$(MANEXT) $(MAN)fbhalf.$(MANEXT) \
  115. X      $(MAN)fbhist.$(MANEXT) $(MAN)fbinfo.$(MANEXT) $(MAN)fbm2pod.$(MANEXT) \
  116. X      $(MAN)fbmask.$(MANEXT) $(MAN)fbnorm.$(MANEXT) $(MAN)fbps.$(MANEXT) \
  117. X      $(MAN)fbquant.$(MANEXT) $(MAN)fbrot.$(MANEXT) $(MAN)fbsample.$(MANEXT) \
  118. X      $(MAN)fbsharp.$(MANEXT) $(MAN)gray2clr.$(MANEXT) $(MAN)idiff.$(MANEXT) \
  119. X      $(MAN)pbm2ps.$(MANEXT) $(MAN)pbmtitle.$(MANEXT) $(MAN)raw2fbm.$(MANEXT) \
  120. X      $(MAN)qrt2fbm.$(MANEXT) $(MAN)fbm.$(MANEXT) $(MAN)fbham.$(MANEXT)
  121. X
  122. XMISC= README Features README.lib Makefile
  123. X
  124. XHDRS= fbm.h
  125. X
  126. Xall: $(EXES)
  127. X
  128. Xinstall: $(BINS) $(MANS)
  129. X
  130. Xuninstall: clean
  131. X    rm -f $(EXES)
  132. X
  133. X# Subroutine library
  134. X
  135. Xlibfbm.a: $(LIBO)
  136. X    rm -f $@
  137. X    ar clq $@ $(LIBO)
  138. X    ranlib $@
  139. X
  140. X# Library routines
  141. Xflalfb.o: flalfb.c fbm.h
  142. X    $(CC) $(DBG) -c flalfb.c
  143. Xflblue.o: flblue.c fbm.h
  144. X    $(CC) $(DBG) -c flblue.c
  145. Xflbyte.o: flbyte.c fbm.h
  146. X    $(CC) $(DBG) -c flbyte.c
  147. Xflcavg.o: flcavg.c fbm.h
  148. X    $(CC) $(DBG) -c flcavg.c
  149. Xflclr.o: flclr.c fbm.h
  150. X    $(CC) $(DBG) -c flclr.c
  151. Xfledge.o: fledge.c fbm.h
  152. X    $(CC) $(DBG) -c fledge.c
  153. Xflextr.o: flextr.c fbm.h
  154. X    $(CC) $(DBG) -c flextr.c
  155. Xflface.o: flface.c fbm.h
  156. X    $(CC) $(DBG) -c flface.c
  157. Xflflyd.o: flflyd.c fbm.h
  158. X    $(CC) $(DBG) -c flflyd.c
  159. Xflgifc.o: flgifc.c fbm.h
  160. X    $(CC) $(DBG) -c flgifc.c
  161. Xflgife.o: flgife.c fbm.h
  162. X    $(CC) $(DBG) -c flgife.c
  163. Xflgifr.o: flgifr.c fbm.h
  164. X    $(CC) $(DBG) -c flgifr.c
  165. Xflgifw.o: flgifw.c fbm.h
  166. X    $(CC) $(DBG) -c flgifw.c
  167. Xfliff.o: fliff.c fbm.h
  168. X    $(CC) $(DBG) -c fliff.c
  169. Xflklnr.o: flklnr.c fbm.h
  170. X    $(CC) $(DBG) -c flklnr.c
  171. Xflpbm.o: flpbm.c fbm.h
  172. X    $(CC) $(DBG) -c flpbm.c
  173. Xflpcx.o: flpcx.c fbm.h
  174. X    $(CC) $(DBG) -c flpcx.c
  175. Xflpic.o: flpic.c fbm.h
  176. X    $(CC) $(DBG) -c flpic.c
  177. Xflrdfb.o: flrdfb.c fbm.h
  178. X    $(CC) $(DBG) -c flrdfb.c
  179. Xflread.o: flread.c fbm.h
  180. X    $(CC) $(DBG) -c flread.c
  181. Xflrot.o: flrot.c fbm.h
  182. X    $(CC) $(DBG) -c flrot.c
  183. Xflshrp.o: flshrp.c fbm.h
  184. X    $(CC) $(DBG) -c flshrp.c
  185. Xflsun.o: flsun.c fbm.h
  186. X    $(CC) $(DBG) -c flsun.c
  187. Xfltga.o: fltga.c fbm.h
  188. X    $(CC) $(DBG) -c fltga.c
  189. Xflthre.o: flthre.c fbm.h
  190. X    $(CC) $(DBG) -c flthre.c
  191. Xflwrfb.o: flwrfb.c fbm.h
  192. X    $(CC) $(DBG) -c flwrfb.c
  193. X
  194. X# Programs
  195. X
  196. Xclr2gray: clr2gray.c fbm.h libfbm.a
  197. X    $(CC) $(DBG) -o clr2gray clr2gray.c $(LIB) -lm
  198. Xfbcat: fbcat.c fbm.h libfbm.a
  199. X    $(CC) $(DBG) -o fbcat fbcat.c $(LIB) -lm
  200. Xfbclean: fbclean.c fbm.h libfbm.a
  201. X    $(CC) $(DBG) -o fbclean fbclean.c $(LIB) -lm
  202. Xfbedge: fbedge.c fbm.h libfbm.a
  203. X    $(CC) $(DBG) -o fbedge fbedge.c $(LIB) -lm
  204. Xfbext: fbext.c fbm.h libfbm.a
  205. X    $(CC) $(DBG) -o fbext fbext.c $(LIB) -lm
  206. Xfbhalf: fbhalf.c fbm.h libfbm.a
  207. X    $(CC) $(DBG) -o fbhalf fbhalf.c $(LIB) -lm
  208. Xfbhist: fbhist.c fbm.h libfbm.a
  209. X    $(CC) $(DBG) -o fbhist fbhist.c $(LIB) -lm
  210. Xfbinfo: fbinfo.c fbm.h libfbm.a
  211. X    $(CC) $(DBG) -o fbinfo fbinfo.c $(LIB) -lm
  212. Xfbm2tga: fbm2tga.c fbm.h libfbm.a
  213. X    $(CC) $(DBG) -o fbm2tga fbm2tga.c $(LIB) -lm
  214. Xtga2fbm: tga2fbm.c fbm.h libfbm.a
  215. X    $(CC) $(DBG) -o tga2fbm tga2fbm.c $(LIB) -lm
  216. Xpic2fbm: pic2fbm.c fbm.h libfbm.a
  217. X    $(CC) $(DBG) -o pic2fbm pic2fbm.c $(LIB) -lm
  218. Xqrt2fbm: qrt2fbm.c fbm.h libfbm.a
  219. X    $(CC) $(DBG) -o qrt2fbm qrt2fbm.c $(LIB) -lm
  220. Xfbm2pod: fbm2pod.c fbm.h libfbm.a
  221. X    $(CC) $(DBG) -o fbm2pod fbm2pod.c $(LIB) -lm
  222. Xfbm2sun: fbm2sun.c fbm.h libfbm.a
  223. X    $(CC) $(DBG) -o fbm2sun fbm2sun.c $(LIB) -lm
  224. Xfbmask: fbmask.c fbm.h libfbm.a
  225. X    $(CC) $(DBG) -o fbmask fbmask.c $(LIB) -lm
  226. Xfbnorm: fbnorm.c fbm.h libfbm.a
  227. X    $(CC) $(DBG) -o fbnorm fbnorm.c $(LIB) -lm
  228. Xfbps: fbps.c fbm.h libfbm.a
  229. X    $(CC) $(DBG) -o fbps fbps.c $(LIB) -lm
  230. Xfbquant: fbquant.c fbm.h libfbm.a
  231. X    $(CC) $(DBG) -o fbquant fbquant.c $(LIB) -lm
  232. Xfbrot: fbrot.c fbm.h libfbm.a
  233. X    $(CC) $(DBG) -o fbrot fbrot.c $(LIB) -lm
  234. Xfbsample: fbsample.c fbm.h libfbm.a
  235. X    $(CC) $(DBG) -o fbsample fbsample.c $(LIB) -lm
  236. Xfbsharp: fbsharp.c fbm.h libfbm.a
  237. X    $(CC) $(DBG) -o fbsharp fbsharp.c $(LIB) -lm
  238. Xgray2clr: gray2clr.c fbm.h libfbm.a
  239. X    $(CC) $(DBG) -o gray2clr gray2clr.c $(LIB) -lm
  240. Xunmap: gray2clr
  241. X    rm -rf unmap
  242. X    ln gray2clr unmap
  243. Xidiff: idiff.c
  244. X    $(CC) $(DBG) -o idiff idiff.c -lm
  245. Xudiff: idiff
  246. X    rm -rf udiff
  247. X    ln idiff udiff
  248. Xpbm2face: pbm2face.c fbm.h libfbm.a
  249. X    $(CC) $(DBG) -o pbm2face pbm2face.c $(LIB) -lm
  250. Xpbm2ps: pbm2ps.c
  251. X    $(CC) $(DBG) -o pbm2ps pbm2ps.c -lm
  252. Xpbmtitle: pbmtitle.c
  253. X    $(CC) $(DBG) -o pbmtitle pbmtitle.c -lm
  254. Xraw2fbm: raw2fbm.c fbm.h libfbm.a
  255. X    $(CC) $(DBG) -o raw2fbm raw2fbm.c $(LIB) -lm
  256. X
  257. X$(BIN)fbext: fbext
  258. X    rm -f $(BIN)fbext
  259. X    $(INSTALL) fbext $(BIN)fbext
  260. X$(BIN)fbrot: fbrot
  261. X    rm -f $(BIN)fbrot
  262. X    $(INSTALL) fbrot $(BIN)fbrot
  263. X$(BIN)fbhist: fbhist
  264. X    rm -f $(BIN)fbhist
  265. X    $(INSTALL) fbhist $(BIN)fbhist
  266. X$(BIN)fbinfo: fbinfo
  267. X    rm -f $(BIN)fbinfo
  268. X    $(INSTALL) fbinfo $(BIN)fbinfo
  269. X$(BIN)fbmask: fbmask
  270. X    rm -f $(BIN)fbmask
  271. X    $(INSTALL) fbmask $(BIN)fbmask
  272. X$(BIN)fbnorm: fbnorm
  273. X    rm -f $(BIN)fbnorm
  274. X    $(INSTALL) fbnorm $(BIN)fbnorm
  275. X$(BIN)fbps: fbps
  276. X    rm -f $(BIN)fbps
  277. X    $(INSTALL) fbps $(BIN)fbps
  278. X$(BIN)fbsharp: fbsharp
  279. X    rm -f $(BIN)fbsharp
  280. X    $(INSTALL) fbsharp $(BIN)fbsharp
  281. X$(BIN)fbedge: fbedge
  282. X    rm -f $(BIN)fbedge
  283. X    $(INSTALL) fbedge $(BIN)fbedge
  284. X$(BIN)fbclean: fbclean
  285. X    rm -f $(BIN)fbclean
  286. X    $(INSTALL) fbclean $(BIN)fbclean
  287. X$(BIN)clr2gray: clr2gray
  288. X    rm -f $(BIN)clr2gray
  289. X    $(INSTALL) clr2gray $(BIN)clr2gray
  290. X$(BIN)fbcat: fbcat
  291. X    rm -f $(BIN)fbcat
  292. X    $(INSTALL) fbcat $(BIN)fbcat
  293. X$(BIN)fbhalf: fbhalf
  294. X    rm -f $(BIN)fbhalf
  295. X    $(INSTALL) fbhalf $(BIN)fbhalf
  296. X$(BIN)fbm2pod: fbm2pod
  297. X    rm -f $(BIN)fbm2pod
  298. X    $(INSTALL) fbm2pod $(BIN)fbm2pod
  299. X$(BIN)fbm2sun: fbm2sun
  300. X    rm -f $(BIN)fbm2sun
  301. X    $(INSTALL) fbm2sun $(BIN)fbm2sun
  302. X$(BIN)fbquant: fbquant
  303. X    rm -f $(BIN)fbquant
  304. X    $(INSTALL) fbquant $(BIN)fbquant
  305. X$(BIN)gray2clr: gray2clr
  306. X    rm -f $(BIN)gray2clr
  307. X    $(INSTALL) gray2clr $(BIN)gray2clr
  308. X$(BIN)unmap: $(BIN)gray2clr
  309. X    rm -f $(BIN)unmap
  310. X    ln $(BIN)gray2clr $(BIN)unmap
  311. X$(BIN)idiff: idiff
  312. X    rm -f $(BIN)idiff
  313. X    $(INSTALL) idiff $(BIN)idiff
  314. X$(BIN)udiff: $(BIN)idiff
  315. X    rm -f $(BIN)udiff
  316. X    ln $(BIN)idiff $(BIN)udiff
  317. X$(BIN)fbsample: fbsample
  318. X    rm -f $(BIN)fbsample
  319. X    $(INSTALL) fbsample $(BIN)fbsample
  320. X$(BIN)qrt2fbm: qrt2fbm
  321. X    rm -f $(BIN)qrt2fbm
  322. X    $(INSTALL) qrt2fbm $(BIN)qrt2fbm
  323. X$(BIN)fbm2tga: fbm2tga
  324. X    rm -f $(BIN)fbm2tga
  325. X    $(INSTALL) fbm2tga $(BIN)fbm2tga
  326. X$(BIN)pic2fbm: pic2fbm
  327. X    rm -f $(BIN)pic2fbm
  328. X    $(INSTALL) pic2fbm $(BIN)pic2fbm
  329. X$(BIN)tga2fbm: tga2fbm
  330. X    rm -f $(BIN)tga2fbm
  331. X    $(INSTALL) tga2fbm $(BIN)tga2fbm
  332. X$(BIN)pbm2ps: pbm2ps
  333. X    rm -f $(BIN)pbm2ps
  334. X    $(INSTALL) pbm2ps $(BIN)pbm2ps
  335. X$(BIN)pbmtitle: pbmtitle
  336. X    rm -f $(BIN)pbmtitle
  337. X    $(INSTALL) pbmtitle $(BIN)pbmtitle
  338. X$(BIN)raw2fbm: raw2fbm
  339. X    rm -f $(BIN)raw2fbm
  340. X    $(INSTALL) raw2fbm $(BIN)raw2fbm
  341. X
  342. X# Manual Entries
  343. X
  344. X$(MAN)clr2gray.$(MANEXT): clr2gray.1
  345. X    rm -f $(MAN)clr2gray.$(MANEXT)
  346. X    $(INSTALL) clr2gray.1 $(MAN)clr2gray.$(MANEXT)
  347. X$(MAN)fbcat.$(MANEXT): fbcat.1
  348. X    rm -f $(MAN)fbcat.$(MANEXT)
  349. X    $(INSTALL) fbcat.1 $(MAN)fbcat.$(MANEXT)
  350. X$(MAN)fbclean.$(MANEXT): fbclean.1
  351. X    rm -f $(MAN)fbclean.$(MANEXT)
  352. X    $(INSTALL) fbclean.1 $(MAN)fbclean.$(MANEXT)
  353. X$(MAN)fbedge.$(MANEXT): fbedge.1
  354. X    rm -f $(MAN)fbedge.$(MANEXT)
  355. X    $(INSTALL) fbedge.1 $(MAN)fbedge.$(MANEXT)
  356. X$(MAN)fbext.$(MANEXT): fbext.1
  357. X    rm -f $(MAN)fbext.$(MANEXT)
  358. X    $(INSTALL) fbext.1 $(MAN)fbext.$(MANEXT)
  359. X$(MAN)fbhalf.$(MANEXT): fbhalf.1
  360. X    rm -f $(MAN)fbhalf.$(MANEXT)
  361. X    $(INSTALL) fbhalf.1 $(MAN)fbhalf.$(MANEXT)
  362. X$(MAN)fbhist.$(MANEXT): fbhist.1
  363. X    rm -f $(MAN)fbhist.$(MANEXT)
  364. X    $(INSTALL) fbhist.1 $(MAN)fbhist.$(MANEXT)
  365. X$(MAN)fbinfo.$(MANEXT): fbinfo.1
  366. X    rm -f $(MAN)fbinfo.$(MANEXT)
  367. X    $(INSTALL) fbinfo.1 $(MAN)fbinfo.$(MANEXT)
  368. X$(MAN)fbm2pod.$(MANEXT): fbm2pod.1
  369. X    rm -f $(MAN)fbm2pod.$(MANEXT)
  370. X    $(INSTALL) fbm2pod.1 $(MAN)fbm2pod.$(MANEXT)
  371. X$(MAN)fbmask.$(MANEXT): fbmask.1
  372. X    rm -f $(MAN)fbmask.$(MANEXT)
  373. X    $(INSTALL) fbmask.1 $(MAN)fbmask.$(MANEXT)
  374. X$(MAN)fbnorm.$(MANEXT): fbnorm.1
  375. X    rm -f $(MAN)fbnorm.$(MANEXT)
  376. X    $(INSTALL) fbnorm.1 $(MAN)fbnorm.$(MANEXT)
  377. X$(MAN)fbps.$(MANEXT): fbps.1
  378. X    rm -f $(MAN)fbps.$(MANEXT)
  379. X    $(INSTALL) fbps.1 $(MAN)fbps.$(MANEXT)
  380. X$(MAN)fbquant.$(MANEXT): fbquant.1
  381. X    rm -f $(MAN)fbquant.$(MANEXT)
  382. X    $(INSTALL) fbquant.1 $(MAN)fbquant.$(MANEXT)
  383. X$(MAN)fbrot.$(MANEXT): fbrot.1
  384. X    rm -f $(MAN)fbrot.$(MANEXT)
  385. X    $(INSTALL) fbrot.1 $(MAN)fbrot.$(MANEXT)
  386. X$(MAN)fbsample.$(MANEXT): fbsample.1
  387. X    rm -f $(MAN)fbsample.$(MANEXT)
  388. X    $(INSTALL) fbsample.1 $(MAN)fbsample.$(MANEXT)
  389. X$(MAN)fbsharp.$(MANEXT): fbsharp.1
  390. X    rm -f $(MAN)fbsharp.$(MANEXT)
  391. X    $(INSTALL) fbsharp.1 $(MAN)fbsharp.$(MANEXT)
  392. X$(MAN)qrt2fbm.$(MANEXT): qrt2fbm.1
  393. X    rm -f $(MAN)qrt2fbm.$(MANEXT)
  394. X    $(INSTALL) qrt2fbm.1 $(MAN)qrt2fbm.$(MANEXT)
  395. X$(MAN)gray2clr.$(MANEXT): gray2clr.1
  396. X    rm -f $(MAN)gray2clr.$(MANEXT)
  397. X    $(INSTALL) gray2clr.1 $(MAN)gray2clr.$(MANEXT)
  398. X$(MAN)idiff.$(MANEXT): idiff.1
  399. X    rm -f $(MAN)idiff.$(MANEXT)
  400. X    $(INSTALL) idiff.1 $(MAN)idiff.$(MANEXT)
  401. X$(MAN)pbm2ps.$(MANEXT): pbm2ps.1
  402. X    rm -f $(MAN)pbm2ps.$(MANEXT)
  403. X    $(INSTALL) pbm2ps.1 $(MAN)pbm2ps.$(MANEXT)
  404. X$(MAN)pbmtitle.$(MANEXT): pbmtitle.1
  405. X    rm -f $(MAN)pbmtitle.$(MANEXT)
  406. X    $(INSTALL) pbmtitle.1 $(MAN)pbmtitle.$(MANEXT)
  407. X$(MAN)raw2fbm.$(MANEXT): raw2fbm.1
  408. X    rm -f $(MAN)raw2fbm.$(MANEXT)
  409. X    $(INSTALL) raw2fbm.1 $(MAN)raw2fbm.$(MANEXT)
  410. X$(MAN)fbm.$(MANEXT): fbm.1
  411. X    rm -f $(MAN)fbm.$(MANEXT)
  412. X    $(INSTALL) fbm.1 $(MAN)fbm.$(MANEXT)
  413. X
  414. X# Miscellaneous things
  415. X
  416. Xclean:
  417. X    rm -f *.o *.CKP *.BAK libfbm.a core
  418. X
  419. Xfluff: $(SRCS)
  420. X    lint $(SRCS) | grep -v 'main multiply declared' | \
  421. X    grep -v 'inconsistently' | grep -v 'ignored' > fluff
  422. X    
  423. X
  424. Xfbm.tar: $(MISC) $(DOCS) $(HDRS) $(SRCS)
  425. X    tar cvf fbm.tar  $(MISC) $(DOCS) $(HDRS) $(SRCS)
  426. X    rm -f $(FTP)fbm.tar.Z $(FTP)fbm$(VER).tar.Z
  427. X    compress < fbm.tar > $(FTP)fbm$(VER).tar.Z
  428. X    ln $(FTP)fbm$(VER).tar.Z $(FTP)fbm.tar.Z
  429. X
  430. Xdist: fbm.01
  431. Xfbm.01: $(MISC) $(DOCS) $(HDRS) $(SRCS)
  432. X    rm -f fbm.??
  433. X    packmail -ofbm -t$(VERSTR) -s50000 \
  434. X    $(MISC) $(DOCS) $(HDRS) $(SRCS)
  435. END_OF_FILE
  436. if test 13166 -ne `wc -c <'Makefile'`; then
  437.     echo shar: \"'Makefile'\" unpacked with wrong size!
  438. fi
  439. # end of 'Makefile'
  440. fi
  441. if test -f 'flgifc.c' -a "${1}" != "-c" ; then 
  442.   echo shar: Will not clobber existing file \"'flgifc.c'\"
  443. else
  444. echo shar: Extracting \"'flgifc.c'\" \(12187 characters\)
  445. sed "s/^X//" >'flgifc.c' <<'END_OF_FILE'
  446. X/*****************************************************************
  447. X * flgifc.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  448. X *
  449. X * Portions of this code Copyright (C) 1989 by Michael Mauldin.
  450. X * Permission is granted to use this file in whole or in part provided
  451. X * that you do not sell it for profit and that this copyright notice
  452. X * and the names of all authors are retained unchanged.
  453. X *
  454. X * flgifc.c:
  455. X *
  456. X * CONTENTS
  457. X *    compress( init_bits, outfile, ReadValue )
  458. X *
  459. X * HISTORY
  460. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  461. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  462. X *
  463. X * 21-Feb-89  Michael Mauldin (mlm) at Carnegie Mellon University
  464. X *    Removed two unused variables found by Lint.
  465. X *
  466. X * 19-Feb-89  Michael Mauldin (mlm) at Carnegie Mellon University
  467. X *    Adapted to FBM package.
  468. X *
  469. X * 13-Feb-89  David Rowley (mgardi@watdcsu.waterloo.edu)
  470. X *    GIF encoding modifications (sent by mail on 2/13/89)
  471. X *    original name: GIFENCODE.C - GIF Image compression interface
  472. X *
  473. X *    Based on: compress.c - File compression ala IEEE Computer, June 1984.
  474. X *
  475. X *    Spencer W. Thomas       (decvax!harpo!utah-cs!utah-gr!thomas)
  476. X *    Jim McKie               (decvax!mcvax!jim)
  477. X *    Steve Davies            (decvax!vax135!petsd!peora!srd)
  478. X *    Ken Turkowski           (decvax!decwrl!turtlevax!ken)
  479. X *    James A. Woods          (decvax!ihnp4!ames!jaw)
  480. X *    Joe Orost               (decvax!vax135!petsd!joe)
  481. X *
  482. X *****************************************************************/
  483. X
  484. X/*
  485. X * General DEFINEs
  486. X */
  487. X#define min(a,b)        ((a>b) ? b : a)
  488. X
  489. X#define BITS    12
  490. X#define MSDOS    1
  491. X
  492. X#define HSIZE  5003            /* 80% occupancy */
  493. X
  494. X/*
  495. X * Pointer to function returning an int
  496. X */
  497. Xtypedef int (* ifunptr)();
  498. X
  499. X/*
  500. X * a code_int must be able to hold 2**BITS values of type int, and also -1
  501. X */
  502. Xtypedef int             code_int;
  503. X
  504. X#ifdef SIGNED_COMPARE_SLOW
  505. Xtypedef unsigned long int count_int;
  506. Xtypedef unsigned short int count_short;
  507. X#else
  508. Xtypedef long int          count_int;
  509. X#endif
  510. X
  511. X#ifdef NO_UCHAR
  512. X typedef char   char_type;
  513. X#else
  514. X typedef        unsigned char   char_type;
  515. X#endif /* UCHAR */
  516. X
  517. X/*
  518. X *
  519. X * GIF Image compression - modified 'compress'
  520. X *
  521. X * Based on: compress.c - File compression ala IEEE Computer, June 1984.
  522. X *
  523. X * By Authors:  Spencer W. Thomas       (decvax!harpo!utah-cs!utah-gr!thomas)
  524. X *              Jim McKie               (decvax!mcvax!jim)
  525. X *              Steve Davies            (decvax!vax135!petsd!peora!srd)
  526. X *              Ken Turkowski           (decvax!decwrl!turtlevax!ken)
  527. X *              James A. Woods          (decvax!ihnp4!ames!jaw)
  528. X *              Joe Orost               (decvax!vax135!petsd!joe)
  529. X *
  530. X */
  531. X#include <stdio.h>
  532. X#include <ctype.h>
  533. X#include <signal.h>
  534. X
  535. X#define ARGVAL() (*++(*argv) || (--argc && *++argv))
  536. X
  537. Xstatic int n_bits;                        /* number of bits/code */
  538. Xstatic int maxbits = BITS;                /* user settable max # bits/code */
  539. Xstatic code_int maxcode;                  /* maximum code, given n_bits */
  540. Xstatic code_int maxmaxcode = (code_int)1 << BITS; /* should NEVER generate this code */
  541. X#ifdef COMPATIBLE               /* But wrong! */
  542. X# define MAXCODE(n_bits)        ((code_int) 1 << (n_bits) - 1)
  543. X#else
  544. X# define MAXCODE(n_bits)        (((code_int) 1 << (n_bits)) - 1)
  545. X#endif /* COMPATIBLE */
  546. X
  547. Xstatic count_int htab [HSIZE];
  548. Xstatic unsigned short codetab [HSIZE];
  549. X#define HashTabOf(i)       htab[i]
  550. X#define CodeTabOf(i)    codetab[i]
  551. X
  552. Xstatic code_int hsize = HSIZE;                 /* for dynamic table sizing */
  553. X
  554. X/*
  555. X * To save much memory, we overlay the table used by compress() with those
  556. X * used by decompress().  The tab_prefix table is the same size and type
  557. X * as the codetab.  The tab_suffix table needs 2**BITS characters.  We
  558. X * get this from the beginning of htab.  The output stack uses the rest
  559. X * of htab, and contains characters.  There is plenty of room for any
  560. X * possible stack (stack used to be 8000 characters).
  561. X */
  562. X
  563. X#define tab_prefixof(i) CodeTabOf(i)
  564. X#define tab_suffixof(i)        ((char_type *)(htab))[i]
  565. X#define de_stack               ((char_type *)&tab_suffixof((code_int)1<<BITS))
  566. X
  567. Xstatic code_int free_ent = 0;                  /* first unused entry */
  568. X
  569. X/*
  570. X * block compression parameters -- after all codes are used up,
  571. X * and compression rate changes, start over.
  572. X */
  573. Xstatic int clear_flg = 0;
  574. X
  575. Xstatic long int in_count = 1;            /* length of input */
  576. Xstatic long int out_count = 0;           /* # of codes output (for debugging) */
  577. X
  578. X/*
  579. X * compress stdin to stdout
  580. X *
  581. X * Algorithm:  use open addressing double hashing (no chaining) on the 
  582. X * prefix code / next character combination.  We do a variant of Knuth's
  583. X * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime
  584. X * secondary probe.  Here, the modular division first probe is gives way
  585. X * to a faster exclusive-or manipulation.  Also do block compression with
  586. X * an adaptive reset, whereby the code table is cleared when the compression
  587. X * ratio decreases, but after the table fills.  The variable-length output
  588. X * codes are re-sized at this point, and a special CLEAR code is generated
  589. X * for the decompressor.  Late addition:  construct the table according to
  590. X * file size for noticeable speed improvement on small files.  Please direct
  591. X * questions about this implementation to ames!jaw.
  592. X */
  593. X
  594. Xstatic int g_init_bits;
  595. Xstatic FILE *g_outfile;
  596. X
  597. Xstatic int ClearCode;
  598. Xstatic int EOFCode;
  599. X
  600. X#ifndef lint
  601. Xstatic char *fbmid =
  602. X    "$FBM flgifc.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  603. X#endif
  604. X
  605. Xcompress( init_bits, outfile, ReadValue )
  606. Xint init_bits;
  607. XFILE *outfile;
  608. Xifunptr ReadValue;
  609. X{
  610. X    register long fcode;
  611. X    register code_int i = 0;
  612. X    register int c;
  613. X    register code_int ent;
  614. X    register code_int disp;
  615. X    register code_int hsize_reg;
  616. X    register int hshift;
  617. X
  618. X    /*
  619. X     * Set up the globals:  g_init_bits - initial number of bits
  620. X     *                      g_outfile   - pointer to output file
  621. X     */
  622. X    g_init_bits = init_bits;
  623. X    g_outfile = outfile;
  624. X
  625. X    /*
  626. X     * Set up the necessary values
  627. X     */
  628. X    out_count = 0;
  629. X    clear_flg = 0;
  630. X    in_count = 1;
  631. X    maxcode = MAXCODE(n_bits = g_init_bits);
  632. X
  633. X    ClearCode = (1 << (init_bits - 1));
  634. X    EOFCode = ClearCode + 1;
  635. X    free_ent = ClearCode + 2;
  636. X
  637. X    char_init();
  638. X    
  639. X    ent = GIFNextPixel( ReadValue );
  640. X
  641. X    hshift = 0;
  642. X    for ( fcode = (long) hsize;  fcode < 65536L; fcode *= 2L )
  643. X        hshift++;
  644. X    hshift = 8 - hshift;                /* set hash code range bound */
  645. X
  646. X    hsize_reg = hsize;
  647. X    cl_hash( (count_int) hsize_reg);            /* clear hash table */
  648. X
  649. X    output( (code_int)ClearCode );
  650. X    
  651. X#ifdef SIGNED_COMPARE_SLOW
  652. X    while ( (c = GIFNextPixel( ReadValue )) != (unsigned) EOF ) {
  653. X#else
  654. X    while ( (c = GIFNextPixel( ReadValue )) != EOF ) {
  655. X#endif
  656. X
  657. X        in_count++;
  658. X
  659. X        fcode = (long) (((long) c << maxbits) + ent);
  660. X        i = (((code_int)c << hshift) ^ ent);    /* xor hashing */
  661. X
  662. X        if ( HashTabOf (i) == fcode ) {
  663. X            ent = CodeTabOf (i);
  664. X            continue;
  665. X        } else if ( (long)HashTabOf (i) < 0 )      /* empty slot */
  666. X            goto nomatch;
  667. X        disp = hsize_reg - i;           /* secondary hash (after G. Knott) */
  668. X        if ( i == 0 )
  669. X            disp = 1;
  670. Xprobe:
  671. X        if ( (i -= disp) < 0 )
  672. X            i += hsize_reg;
  673. X
  674. X        if ( HashTabOf (i) == fcode ) {
  675. X            ent = CodeTabOf (i);
  676. X            continue;
  677. X        }
  678. X        if ( (long)HashTabOf (i) > 0 ) 
  679. X            goto probe;
  680. Xnomatch:
  681. X        output ( (code_int) ent );
  682. X        out_count++;
  683. X        ent = c;
  684. X#ifdef SIGNED_COMPARE_SLOW
  685. X        if ( (unsigned) free_ent < (unsigned) maxmaxcode) {
  686. X#else
  687. X        if ( free_ent < maxmaxcode ) {
  688. X#endif
  689. X            CodeTabOf (i) = free_ent++; /* code -> hashtable */
  690. X            HashTabOf (i) = fcode;
  691. X        } else
  692. X        cl_block();
  693. X    }
  694. X    /*
  695. X     * Put out the final code.
  696. X     */
  697. X    output( (code_int)ent );
  698. X    out_count++;
  699. X    output( (code_int) EOFCode );
  700. X
  701. X    return;
  702. X}
  703. X
  704. X/*****************************************************************
  705. X * TAG( output )
  706. X *
  707. X * Output the given code.
  708. X * Inputs:
  709. X *      code:   A n_bits-bit integer.  If == -1, then EOF.  This assumes
  710. X *              that n_bits =< (long)wordsize - 1.
  711. X * Outputs:
  712. X *      Outputs code to the file.
  713. X * Assumptions:
  714. X *      Chars are 8 bits long.
  715. X * Algorithm:
  716. X *      Maintain a BITS character long buffer (so that 8 codes will
  717. X * fit in it exactly).  Use the VAX insv instruction to insert each
  718. X * code in turn.  When the buffer fills up empty it and start over.
  719. X */
  720. X
  721. Xstatic unsigned long cur_accum = 0;
  722. Xstatic int  cur_bits = 0;
  723. X
  724. Xstatic
  725. Xunsigned long masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F,
  726. X                                  0x001F, 0x003F, 0x007F, 0x00FF,
  727. X                                  0x01FF, 0x03FF, 0x07FF, 0x0FFF,
  728. X                                  0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
  729. X
  730. Xstatic
  731. Xoutput( code )
  732. Xcode_int  code;
  733. X{
  734. X    cur_accum &= masks[ cur_bits ];
  735. X
  736. X    if( cur_bits > 0 )
  737. X        cur_accum |= ((long)code << cur_bits);
  738. X    else
  739. X        cur_accum = code;
  740. X    
  741. X    cur_bits += n_bits;
  742. X
  743. X    while( cur_bits >= 8 ) {
  744. X        char_out( (unsigned int)(cur_accum & 0xff) );
  745. X    cur_accum >>= 8;
  746. X    cur_bits -= 8;
  747. X    }
  748. X
  749. X    /*
  750. X     * If the next entry is going to be too big for the code size,
  751. X     * then increase it, if possible.
  752. X     */
  753. X   if ( free_ent > maxcode || clear_flg ) {
  754. X
  755. X            if( clear_flg ) {
  756. X        
  757. X                maxcode = MAXCODE (n_bits = g_init_bits);
  758. X                clear_flg = 0;
  759. X        
  760. X            } else {
  761. X        
  762. X                n_bits++;
  763. X                if ( n_bits == maxbits )
  764. X                    maxcode = maxmaxcode;
  765. X                else
  766. X                    maxcode = MAXCODE(n_bits);
  767. X            }
  768. X        }
  769. X    
  770. X    if( code == EOFCode ) {
  771. X        /*
  772. X         * At EOF, write the rest of the buffer.
  773. X         */
  774. X        while( cur_bits > 0 ) {
  775. X                char_out( (unsigned int)(cur_accum & 0xff) );
  776. X            cur_accum >>= 8;
  777. X            cur_bits -= 8;
  778. X        }
  779. X
  780. X    flush_char();
  781. X    
  782. X        fflush( g_outfile );
  783. X
  784. X    if( ferror( g_outfile ) )
  785. X                writeerr();
  786. X    }
  787. X}
  788. X
  789. X/*
  790. X * Clear out the hash table
  791. X */
  792. Xstatic
  793. Xcl_block ()             /* table clear for block compress */
  794. X{
  795. X
  796. X        cl_hash ( (count_int) hsize );
  797. X        free_ent = ClearCode + 2;
  798. X        clear_flg = 1;
  799. X
  800. X        output( (code_int)ClearCode );
  801. X}
  802. X
  803. Xstatic
  804. Xcl_hash(hsize)          /* reset code table */
  805. Xregister count_int hsize;
  806. X{
  807. X
  808. X        register count_int *htab_p = htab+hsize;
  809. X
  810. X        register long i;
  811. X        register long m1 = -1;
  812. X
  813. X        i = hsize - 16;
  814. X        do {                            /* might use Sys V memset(3) here */
  815. X                *(htab_p-16) = m1;
  816. X                *(htab_p-15) = m1;
  817. X                *(htab_p-14) = m1;
  818. X                *(htab_p-13) = m1;
  819. X                *(htab_p-12) = m1;
  820. X                *(htab_p-11) = m1;
  821. X                *(htab_p-10) = m1;
  822. X                *(htab_p-9) = m1;
  823. X                *(htab_p-8) = m1;
  824. X                *(htab_p-7) = m1;
  825. X                *(htab_p-6) = m1;
  826. X                *(htab_p-5) = m1;
  827. X                *(htab_p-4) = m1;
  828. X                *(htab_p-3) = m1;
  829. X                *(htab_p-2) = m1;
  830. X                *(htab_p-1) = m1;
  831. X                htab_p -= 16;
  832. X        } while ((i -= 16) >= 0);
  833. X
  834. X    for ( i += 16; i > 0; i-- )
  835. X                *--htab_p = m1;
  836. X}
  837. X
  838. Xstatic
  839. Xwriteerr()
  840. X{
  841. X    printf( "error writing output file\n" );
  842. X    exit(1);
  843. X}
  844. X
  845. X/******************************************************************************
  846. X *
  847. X * GIF Specific routines
  848. X *
  849. X ******************************************************************************/
  850. X
  851. X/*
  852. X * Number of characters so far in this 'packet'
  853. X */
  854. Xstatic int a_count;
  855. X
  856. X/*
  857. X * Set up the 'byte output' routine
  858. X */
  859. Xstatic
  860. Xchar_init()
  861. X{
  862. X    a_count = 0;
  863. X}
  864. X
  865. X/*
  866. X * Define the storage for the packet accumulator
  867. X */
  868. Xstatic char accum[ 256 ];
  869. X
  870. X/*
  871. X * Add a character to the end of the current packet, and if it is 254
  872. X * characters, flush the packet to disk.
  873. X */
  874. Xstatic
  875. Xchar_out( c )
  876. Xint c;
  877. X{
  878. X    accum[ a_count++ ] = c;
  879. X    if( a_count >= 254 ) 
  880. X        flush_char();
  881. X}
  882. X
  883. X/*
  884. X * Flush the packet to disk, and reset the accumulator
  885. X */
  886. Xstatic
  887. Xflush_char()
  888. X{
  889. X    if( a_count > 0 ) {
  890. X        fputc( a_count, g_outfile );
  891. X        fwrite( accum, 1, a_count, g_outfile );
  892. X        a_count = 0;
  893. X    }
  894. X}    
  895. X
  896. X/* The End */
  897. X
  898. END_OF_FILE
  899. if test 12187 -ne `wc -c <'flgifc.c'`; then
  900.     echo shar: \"'flgifc.c'\" unpacked with wrong size!
  901. fi
  902. # end of 'flgifc.c'
  903. fi
  904. if test -f 'flpcx.c' -a "${1}" != "-c" ; then 
  905.   echo shar: Will not clobber existing file \"'flpcx.c'\"
  906. else
  907. echo shar: Extracting \"'flpcx.c'\" \(9151 characters\)
  908. sed "s/^X//" >'flpcx.c' <<'END_OF_FILE'
  909. X/*****************************************************************
  910. X * flpcx.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  911. X *
  912. X * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  913. X * use this file in whole or in part provided that you do not sell it
  914. X * for profit and that this copyright notice is retained unchanged.
  915. X *
  916. X * flpcx.c: 
  917. X *
  918. X * CONTENTS
  919. X *    write_pcx (image, stream)
  920. X *    read_pcx (image, stream, mstr, mlen)
  921. X *
  922. X * EDITLOG
  923. X *    LastEditDate = Tue Mar  7 19:57:24 1989 - Michael Mauldin
  924. X *    LastFileName = /usr2/mlm/src/misc/fbm/flpcx.c
  925. X *
  926. X * HISTORY
  927. X * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  928. X *    Beta release (version 0.9) mlm@cs.cmu.edu
  929. X *
  930. X * 12-Nov-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  931. X *    Created.
  932. X *****************************************************************/
  933. X
  934. X# include <stdio.h>
  935. X# include <math.h>
  936. X# include <ctype.h>
  937. X# include "fbm.h"
  938. X
  939. X/****************************************************************
  940. X * pcx.h: Paintbrush file format header, as per "ZSoft Technical
  941. X *    Reference Manual for Publisher's Paintbrush, PC Paintbrush Plus,
  942. X *    PC Paintbrush and Frieze Graphics.", 1988,  ZSoft corporation,
  943. X *
  944. X *    450 Franklin Rd. Suite 100 / Marietta, GA  30067 / 404-428-0008
  945. X *
  946. X * HISTORY
  947. X * {1}     1-Sep-87  Michael L. Mauldin (mlm) at cognac
  948. X *     Created.
  949. X * 
  950. X ****************************************************************/
  951. X
  952. X# define UBYTE    unsigned char    /*  8 bits unsigned        */
  953. X# define WORD    short        /* 16 bits signed        */
  954. X
  955. Xtypedef struct pcxstruct {
  956. X  UBYTE    Manufacturer;        /* 10 == ZSoft PCX        */
  957. X  UBYTE    Version;        /* Version Information        */
  958. X                /*    0 == ver 2.5        */
  959. X                /*    2 == ver 2.8 w/pallete    */
  960. X                /*    3 == 2.8 w/o pallete    */
  961. X                /*    5 == ver 3.0 w/pallete    */
  962. X  UBYTE    Encoding;        /* 01 == PCX run-length encoding */
  963. X  UBYTE    BitsPerPixel;        /* 8/number of pixels per byte    */
  964. X  WORD    Window[4];        /* xmin, ymin, xmax, ymax    */
  965. X  WORD    Hres;            /* Horizontal resolution    */
  966. X  WORD    Vres;            /* Vertical resolution        */
  967. X  UBYTE    Colormap[16][3];    /* Color Pallete, RGB in 0..255    */
  968. X  UBYTE    Reserved;        /* Reserved            */
  969. X  UBYTE NPlanes;        /* Number of Color Planes    */
  970. X  WORD    BytesPerLine;        /* Number of bytes per scan line */
  971. X  WORD    Palette;        /* 1 = color/BW, 2 = grayscale  */
  972. X  UBYTE    Filler[58];        /* Pad header to 128 bytes    */
  973. X} PCXHDR;
  974. X
  975. X# define XMIN 0
  976. X# define YMIN 1
  977. X# define XMAX 2
  978. X# define YMAX 3
  979. X
  980. X# define CNTMSK 0xc0
  981. X# define MAXCNT 0x3f
  982. X
  983. X# define swapword(X) ((((X)&0xff) << 8) | (((X) & 0xff00) >> 8))
  984. X
  985. X/****************************************************************
  986. X * write_pcx: Write PC Paintbrush format
  987. X ****************************************************************/
  988. X
  989. X#ifndef lint
  990. Xstatic char *fbmid =
  991. X    "$FBM flpcx.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  992. X#endif
  993. X
  994. Xwrite_pcx (image, stream)
  995. XFBM *image;
  996. XFILE *stream;
  997. X{  
  998. X  fprintf (stderr, "PCX support not yet available\n");
  999. X
  1000. X  return (0);
  1001. X}
  1002. X
  1003. X/****************************************************************
  1004. X * read_pcx: Read PC Paintbrush format
  1005. X ****************************************************************/
  1006. X
  1007. Xread_pcx (image, rfile, mstr, mlen)
  1008. XFBM *image;
  1009. XFILE *rfile;
  1010. Xchar *mstr;
  1011. Xint mlen;
  1012. X{ PCXHDR phdr;
  1013. X  char *hp;
  1014. X  register unsigned char *bmp, *scan;
  1015. X  register int k, r, c, bit, byte, mask, width, height, rowlen;
  1016. X  int depth, ptype, color, enc, clrlen, totalbytes;
  1017. X  unsigned char *buf, *tail;
  1018. X
  1019. X  /* Read PCX file header */
  1020. X  hp = (char *) &phdr;
  1021. X
  1022. X  if (mlen > 0) strncpy (hp, mstr, mlen);
  1023. X
  1024. X  if (! fread (hp+mlen, sizeof (phdr) - mlen, 1, rfile))
  1025. X  { perror ("read_fbm (header)"); return (0); }
  1026. X
  1027. X  if (phdr.Manufacturer != PCX_MAGIC)
  1028. X  { fprintf (stderr,
  1029. X         "Error, file is not a PCX file, magic %02x is not 0a\n",
  1030. X          phdr.Manufacturer);
  1031. X    return (0);
  1032. X  }
  1033. X  
  1034. X  /* PCX uses Little Indian byte order, swap on SUNS, RTs, ... */
  1035. X  if (machine_byte_order () == BIG)
  1036. X  { phdr.Window[0] =     swapword (phdr.Window[0]);
  1037. X    phdr.Window[1] =     swapword (phdr.Window[1]);
  1038. X    phdr.Window[2] =     swapword (phdr.Window[2]);
  1039. X    phdr.Window[3] =     swapword (phdr.Window[3]);
  1040. X    phdr.Hres =          swapword (phdr.Hres);
  1041. X    phdr.Vres =          swapword (phdr.Vres);
  1042. X    phdr.BytesPerLine =  swapword (phdr.BytesPerLine);
  1043. X    phdr.Palette =  swapword (phdr.Palette);
  1044. X  }
  1045. X  
  1046. X# ifdef DEBUG
  1047. X  fprintf (stderr, "Manufacturer        %d\n", phdr.Manufacturer);
  1048. X  fprintf (stderr, "Version             %d\n", phdr.Version);
  1049. X  fprintf (stderr, "Encoding            %d\n", phdr.Encoding);
  1050. X  fprintf (stderr, "BitsPerPixel        %d\n", phdr.BitsPerPixel);
  1051. X  fprintf (stderr, "Window0             %d\n", phdr.Window[0]);
  1052. X  fprintf (stderr, "Window1             %d\n", phdr.Window[1]);
  1053. X  fprintf (stderr, "Window2             %d\n", phdr.Window[2]);
  1054. X  fprintf (stderr, "Window3             %d\n", phdr.Window[3]);
  1055. X  fprintf (stderr, "Hres                %d\n", phdr.Hres);
  1056. X  fprintf (stderr, "Vres                %d\n", phdr.Vres);
  1057. X  fprintf (stderr, "Reserved            %d\n", phdr.Reserved);
  1058. X  fprintf (stderr, "NPlanes             %d\n", phdr.NPlanes);
  1059. X  fprintf (stderr, "BytesPerLine        %d\n", phdr.BytesPerLine);
  1060. X  fprintf (stderr, "Palette             %d\n", phdr.Palette);
  1061. X# endif
  1062. X
  1063. X  /* Now extract relevant features of PCX file header */
  1064. X  width =  phdr.Window[XMAX] - phdr.Window[XMIN] + 1;
  1065. X  height = phdr.Window[YMAX] - phdr.Window[YMIN] + 1;
  1066. X  depth =  phdr.NPlanes;
  1067. X  ptype =  phdr.Version;
  1068. X  color =  (ptype == 2) || (ptype == 5);
  1069. X  enc =    phdr.Encoding;
  1070. X
  1071. X  if (phdr.BitsPerPixel != 1)
  1072. X  { fprintf (stderr, "%s %d bits per pixel with %d planes\n", 
  1073. X         "Error in PCX file, can't handle", 
  1074. X         phdr.BitsPerPixel, depth);
  1075. X    return (0);
  1076. X  }
  1077. X
  1078. X  /* Initialize image header */
  1079. X  image->hdr.cols = width;
  1080. X  image->hdr.rows = height;
  1081. X  image->hdr.planes = 1;
  1082. X  image->hdr.bits = (color || depth > 1) ? 8 : 1;
  1083. X  image->hdr.physbits = 8;
  1084. X  image->hdr.rowlen = rowlen = 16 * ((width + 15) / 16);
  1085. X  image->hdr.plnlen = rowlen * height;
  1086. X  image->hdr.clrlen = clrlen = color ? (16 * 3) : 0;
  1087. X  image->hdr.aspect = 1.0;
  1088. X  image->hdr.title[0] = '\0';
  1089. X  image->hdr.credits[0] = '\0';
  1090. X
  1091. X  /* Describe what we are doing */
  1092. X  fprintf (stderr, "Reading PCX file [%dx%d]", width, height);
  1093. X  if (phdr.BitsPerPixel > 1)
  1094. X    fprintf (stderr, ", %d bits per pixel", phdr.BitsPerPixel);
  1095. X  if (depth > 1)
  1096. X    fprintf (stderr, ", %d planes", depth);
  1097. X  if (clrlen > 0)
  1098. X    fprintf (stderr, ", %d colors", clrlen/3);
  1099. X  fprintf (stderr, "\n");
  1100. X
  1101. X  /* Allocate space */
  1102. X  alloc_fbm (image);
  1103. X
  1104. X  /* Read colormap if need be */
  1105. X  if (clrlen > 0)
  1106. X  { for (c=0; c<16; c++)
  1107. X    { image->cm[c]    = phdr.Colormap[c][0];
  1108. X      image->cm[c+16] = phdr.Colormap[c][1];
  1109. X      image->cm[c+32] = phdr.Colormap[c][2];
  1110. X    }
  1111. X  }
  1112. X
  1113. X  /* Zero out the bits */
  1114. X  bmp = image->bm;
  1115. X  tail = bmp + image->hdr.plnlen;
  1116. X
  1117. X  while (bmp < tail) { *bmp++ = 0; }
  1118. X  
  1119. X  /* Bytes per scan line */
  1120. X  totalbytes = depth * phdr.BytesPerLine;
  1121. X  buf = (unsigned char *) malloc (totalbytes);
  1122. X
  1123. X  /* Now read bits */
  1124. X  for (r=0; r<height; r++)
  1125. X  { bmp = &(image->bm[r * rowlen]);
  1126. X  
  1127. X    /* Read a scan line */
  1128. X    if (pcxline_read (enc, buf, totalbytes, rfile) == 0)
  1129. X    { fprintf (stderr, "Premature EOF in row %d, totalbytes %d\n",
  1130. X        r, totalbytes);
  1131. X# ifdef REAL
  1132. X      free_fbm (image);
  1133. X      return (0);
  1134. X# else
  1135. X      return (1);
  1136. X# endif
  1137. X    }
  1138. X        
  1139. X    /* Decode scan line into row of image */
  1140. X    if (depth == 1)
  1141. X    { bmp = &(image->bm[r * rowlen]);
  1142. X      scan = buf;
  1143. X
  1144. X      for (c=0; c<width; c++)
  1145. X      { byte = c>>3;
  1146. X    mask = 0x80 >> (c&7);
  1147. X    *bmp++ = (buf[byte] & mask) ? WHITE : BLACK;
  1148. X      }
  1149. X    }
  1150. X    else
  1151. X    { for (k=0; k<depth; k++)
  1152. X      { bmp = &(image->bm[r * rowlen]);
  1153. X        scan = &buf[k * phdr.BytesPerLine];
  1154. X    bit = 1 << k;
  1155. X
  1156. X        for (c=0; c<width; c++)
  1157. X    { byte = c>>3;
  1158. X      mask = 0x80 >> (c&7);
  1159. X
  1160. X      *bmp++ |= (buf[byte] & mask) ? bit : 0;
  1161. X        }
  1162. X      }
  1163. X    }
  1164. X  }
  1165. X
  1166. X  if (depth > 1)
  1167. X  { fprintf (stderr, "Read %d planes successfully\n", depth);
  1168. X  }
  1169. X
  1170. X  return (1);
  1171. X}
  1172. X
  1173. X/****************************************************************
  1174. X * encget (pbyt, pcnt, fid)    Page 10 of ZSoft Manual
  1175. X ****************************************************************/
  1176. X
  1177. Xencget (pbyt, pcnt, fid)
  1178. Xint *pbyt;    /* Where to place data */
  1179. Xint *pcnt;    /* Where to place count */
  1180. XFILE *fid;    /* Image file stream */
  1181. X{ register int i;
  1182. X
  1183. X  *pcnt = 1;        /* Safety play */
  1184. X  if (EOF == (i = getc (fid))) return (EOF);
  1185. X  if (CNTMSK == (CNTMSK & i))
  1186. X  { *pcnt = MAXCNT & i;
  1187. X    if (EOF == (i = getc (fid))) return (EOF);
  1188. X  }
  1189. X  *pbyt = i;
  1190. X  return (0);
  1191. X}
  1192. X
  1193. X/****************************************************************
  1194. X * pcxline_read
  1195. X ****************************************************************/
  1196. Xpcxline_read (enc, buf, total, fid)
  1197. Xunsigned char *buf;    /* Output buffer */
  1198. Xint total;        /* Bytes in one scan line */
  1199. XFILE *fid;        /* Input stream */
  1200. X{ int data, count, len=0;
  1201. X
  1202. X  if (enc != 1)
  1203. X  { return (fread (buf, 1, total, fid)); }
  1204. X
  1205. X  while (len < total)
  1206. X  { if (EOF == encget (&data, &count, fid))
  1207. X      return (len);
  1208. X    while (count > 0) { *buf++ = data; len++; count--; }
  1209. X  }
  1210. X  
  1211. X  if (count > 0)
  1212. X  { fprintf (stderr, "%s, after %d bytes, lost %d bytes of %02x\n",
  1213. X         "Error in reading scan lines", total, count, data);
  1214. X  }
  1215. X
  1216. X  return (len);
  1217. X}
  1218. END_OF_FILE
  1219. if test 9151 -ne `wc -c <'flpcx.c'`; then
  1220.     echo shar: \"'flpcx.c'\" unpacked with wrong size!
  1221. fi
  1222. # end of 'flpcx.c'
  1223. fi
  1224. if test -f 'fltga.c' -a "${1}" != "-c" ; then 
  1225.   echo shar: Will not clobber existing file \"'fltga.c'\"
  1226. else
  1227. echo shar: Extracting \"'fltga.c'\" \(13220 characters\)
  1228. sed "s/^X//" >'fltga.c' <<'END_OF_FILE'
  1229. X/*****************************************************************
  1230. X * fltga.c: FBM Library 0.93 (Beta Test) 03-May-89  Ian MacPhedran
  1231. X *
  1232. X * Author Ian MacPhedran.
  1233. X * Permission is given to use any portion of this file, (including
  1234. X * its entirety) for whatever you wish. Howvever, please note that
  1235. X * it was written for Michael Mauldin's FBM Library, and conditions
  1236. X * therein are more restrictive.
  1237. X *
  1238. X * CONTENTS
  1239. X *    read_tga (image, rfile, mstr, mlen)
  1240. X *    write_tga (image, wfile)
  1241. X *
  1242. X * EDITLOG
  1243. X *    LastEditDate = Sat May 20 19:53:58 1989 - Michael Mauldin
  1244. X *    LastFileName = /usr2/mlm/src/misc/fbm/fltga.c
  1245. X *
  1246. X * HISTORY
  1247. X * 03-May-89  Michael Mauldin (mlm) at Carnegie Mellon University
  1248. X *    Beta release (version 0.93) mlm@cs.cmu.edu
  1249. X *
  1250. X * HISTORY
  1251. X * 13-Mar-89  Ian J. MacPhedran
  1252. X *    Add write_tga
  1253. X *
  1254. X * 07-Mar-89  Ian J. MacPhedran, University of Saskatchewan.
  1255. X *    Created.
  1256. X *****************************************************************/
  1257. X
  1258. X#include <stdio.h>
  1259. X#include "fbm.h"
  1260. X
  1261. X#ifndef lint
  1262. Xstatic char *fbmid =
  1263. X    "$FBM fltga.c <0.93> 03-May-89  (C) 1989 by Ian MacPhedran$";
  1264. X#endif
  1265. X
  1266. X
  1267. X/* For convenience, the TGA header file is included herein. */
  1268. X
  1269. X/*
  1270. X * Header file for Targa file definitions.
  1271. X *
  1272. X * These definitions will allow a consistant interface to build Targa (.TGA)
  1273. X * image files.
  1274. X *
  1275. X * Created NOV-15-1988 IJMP
  1276. X *
  1277. X */
  1278. X/* File header definition */
  1279. X
  1280. Xstruct TGA_ImageHeader {
  1281. X        unsigned char IDLength;/* Length of Identifier String */
  1282. X        unsigned char CoMapType; /* 0 = NoMap */
  1283. X        unsigned char ImgType;    /* Image Type (1,2,3,9,10) */
  1284. X        unsigned char Index_lo, Index_hi;
  1285. X            /* Index of first colour map entry */
  1286. X        unsigned char Length_lo, Length_hi;
  1287. X            /* Length of colour map (number of entries) */
  1288. X        unsigned char CoSize;    /* Length of colour map entry */
  1289. X        unsigned char X_org_lo, X_org_hi;    /* X Origin of Image */
  1290. X        unsigned char Y_org_lo, Y_org_hi;    /* Y Origin of Image */
  1291. X        unsigned char Width_lo, Width_hi;    /* Width of Image */
  1292. X        unsigned char Height_lo, Height_hi;    /* Height of Image */
  1293. X        unsigned char PixelSize;    /* Pixel Size (8,16,24) */
  1294. X        unsigned AttBits : 4;    /* Number of Attribute Bits per pixel */
  1295. X        unsigned Rsrvd   : 1;    /* Reserved bit */
  1296. X        unsigned OrgBit  : 1;
  1297. X            /* Origin Bit (0=lower left, 1=upper left) */
  1298. X        unsigned IntrLve : 2;    /* Interleaving Flag */
  1299. X        };
  1300. X
  1301. Xchar TGA_ImageIDField[256];
  1302. X
  1303. X/* Definitions for Image Types */
  1304. X
  1305. X#define TGA_MapRGBType 1
  1306. X#define TGA_RawRGBType 2
  1307. X#define TGA_RawMonoType 3
  1308. X#define TGA_MapEnCodeType 9
  1309. X#define TGA_RawEnCodeType 10
  1310. X
  1311. X/*
  1312. X * read_tga(image, rfile, mstr, mlen)
  1313. X * from tga2rast.c:
  1314. X * Version 1.0 - first released for public consumption, 21 Feb, 1989
  1315. X *
  1316. X */
  1317. X
  1318. X#define MAXCOLOURS 16384
  1319. X
  1320. X/* Define flags for mode - these indicate special conditions */
  1321. X#define GREYSC 0
  1322. X#define COLOUR 1
  1323. X#define MAPPED 2
  1324. X#define RLENCD 4
  1325. X#define INTERL 8
  1326. X#define FOURWY 16
  1327. X
  1328. Xunsigned char ColourMap[MAXCOLOURS][3];
  1329. Xint RLE_count=0,RLE_flag=0;
  1330. X
  1331. Xread_tga(image, rfile, mstr, mlen)
  1332. XFBM *image;
  1333. XFILE *rfile;
  1334. Xchar *mstr;
  1335. Xint mlen;
  1336. X{
  1337. X/* Define Identifiers */
  1338. Xstruct TGA_ImageHeader    *tga;
  1339. Xint            i, j;
  1340. Xunsigned int        temp1, temp2, mode;
  1341. Xunsigned char        r, g, b;
  1342. Xunsigned long        k, baseline,linewidth;
  1343. Xunsigned char        *Red, *Grn, *Blu, *Redk, *Grnk, *Bluk;
  1344. X
  1345. X/* Input the Targa file header */
  1346. X    if ((tga=(struct TGA_ImageHeader *)
  1347. X         malloc(sizeof(struct TGA_ImageHeader))) == NULL)
  1348. X    {
  1349. X        fprintf(stderr,"Can't allocate TGA memory\n");
  1350. X        exit(1);
  1351. X    }
  1352. X
  1353. X    if ((i = fread(tga,1,18,rfile)) != 18)
  1354. X    {
  1355. X        fprintf(stderr,"Read only %d bytes in header\n",i);
  1356. X        exit(1);
  1357. X    }
  1358. X    switch (tga->ImgType)
  1359. X    {
  1360. X        case TGA_MapRGBType:
  1361. X        case TGA_RawRGBType:
  1362. X        case TGA_RawMonoType:
  1363. X        case TGA_MapEnCodeType:
  1364. X        case TGA_RawEnCodeType:
  1365. X            break;
  1366. X
  1367. X        default:
  1368. X            fprintf(stderr,"Targa File Type %d",tga->ImgType);
  1369. X            fprintf(stderr," not supported!\n");
  1370. X            exit(1);
  1371. X    }
  1372. X
  1373. X/* Create output image header */
  1374. X    temp1 = tga->Height_lo; temp2 = tga->Height_hi;
  1375. X    image->hdr.rows = temp1 + temp2 * 256;
  1376. X    temp1 = tga->Width_lo; temp2 = tga->Width_hi;
  1377. X    image->hdr.cols = temp1 + temp2 * 256;
  1378. X    /* If this is odd number of bytes, add one */
  1379. X    if ((image->hdr.cols & 1) != 0) image->hdr.cols++;
  1380. X
  1381. X/* If greyscale, use only one plane */
  1382. X    if (tga->ImgType == TGA_RawMonoType)
  1383. X    {
  1384. X        image->hdr.planes = 1;
  1385. X        mode = GREYSC;
  1386. X    }
  1387. X    else
  1388. X    {
  1389. X        image->hdr.planes = 3;
  1390. X        mode = COLOUR;
  1391. X    }
  1392. X
  1393. X/* Uses 8 bits, sort of - 16 bits/pixel is 5 bits per colour */
  1394. X    image->hdr.bits = 8;
  1395. X    image->hdr.physbits = 8;
  1396. X    image->hdr.rowlen = image->hdr.cols;
  1397. X    image->hdr.plnlen = image->hdr.rows * image->hdr.cols;
  1398. X/* Ignore colour map for this version. */
  1399. X    image->hdr.clrlen = 0;
  1400. X    image->hdr.aspect = 1.0;
  1401. X    image->hdr.title[0] = '\0';
  1402. X    image->hdr.credits[0] = '\0';
  1403. X
  1404. X/* Get the Image */
  1405. X    alloc_fbm(image);
  1406. X
  1407. X/* Read ID String, if present */
  1408. X    if (tga->IDLength != 0)
  1409. X        fread(TGA_ImageIDField,1,tga->IDLength,rfile);
  1410. X
  1411. X/* If present, read the colour map information */
  1412. X        if (tga->CoMapType != 0)
  1413. X        {
  1414. X        temp1 = tga->Index_lo + tga->Index_hi * 256;
  1415. X        temp2 = tga->Length_lo + tga->Length_hi * 256;
  1416. X        if ((temp1+temp2+1) >= MAXCOLOURS)
  1417. X        {
  1418. X            fprintf(stderr,"Too many colours %d\n",(temp1+temp2+1));
  1419. X            exit(1);
  1420. X        }
  1421. X        for (i=temp1; i<(temp1+temp2); i++)
  1422. X            get_map_entry(&ColourMap[i][0],&ColourMap[i][1],
  1423. X            &ColourMap[i][2],tga->CoSize,mode);
  1424. X        if ((tga->ImgType != TGA_RawRGBType) &&
  1425. X            (tga->ImgType != TGA_RawMonoType) &&
  1426. X            (tga->ImgType != TGA_RawEnCodeType))
  1427. X            mode = mode | MAPPED;
  1428. X    }
  1429. X
  1430. X/* Check Run Length Encoding */
  1431. X    if ((tga->ImgType == TGA_MapEnCodeType) || 
  1432. X        (tga->ImgType == TGA_RawEnCodeType))
  1433. X        mode = mode | RLENCD;
  1434. X
  1435. X/* Check for interlacing of the Targa file */
  1436. X    switch (tga->IntrLve)
  1437. X    {
  1438. X        case 2: /* Four way interlace */
  1439. X            mode = mode | FOURWY;
  1440. X        case 1: /* Two way interlace */
  1441. X            mode = mode | INTERL;
  1442. X        case 0: /* No interlace */
  1443. X            break;
  1444. X        default: /* Reserved - we'll let it pass */
  1445. X            break;
  1446. X    }
  1447. X
  1448. X/* Set up byte map for writing */
  1449. X
  1450. X    Red = image->bm;
  1451. X    if ((mode & COLOUR) != GREYSC)
  1452. X    {
  1453. X        Grn = Red + image->hdr.plnlen;
  1454. X        Blu = Grn + image->hdr.plnlen;
  1455. X    }
  1456. X/* Read the Targa file body and convert to image format */
  1457. X    linewidth = tga->Width_lo + tga->Width_hi * 256;
  1458. X    for (i=0; i< image->hdr.rows; i++)
  1459. X    {
  1460. X        /* No interlace */
  1461. X        if ((mode & INTERL) == 0)
  1462. X        {
  1463. X            j = i;
  1464. X        }
  1465. X        /* Two way interlace */
  1466. X        else if ((mode & FOURWY) != 0)
  1467. X        {
  1468. X            if (2*i < image->hdr.rows)
  1469. X                j = 2*i;
  1470. X            else
  1471. X            {
  1472. X                j = i - image->hdr.rows/2;
  1473. X                j = 2*j + 1;
  1474. X            }
  1475. X        }
  1476. X        /* Four way interlace */
  1477. X        else
  1478. X        {
  1479. X            if (4*i < image->hdr.rows)
  1480. X                j = 4*i;
  1481. X            else if (2*i < image->hdr.rows)
  1482. X            {
  1483. X                j = i - image->hdr.rows/4;
  1484. X                j = 4*j + 1;
  1485. X            }
  1486. X            else if (4*i < 3*image->hdr.rows)
  1487. X            {
  1488. X                j = i - image->hdr.rows/2;
  1489. X                j = 4*j + 2;
  1490. X            }
  1491. X            else
  1492. X            {
  1493. X                j = i - image->hdr.rows/2 - image->hdr.rows/4;
  1494. X                j = 4*j + 3;
  1495. X            }
  1496. X        }
  1497. X        k = (image->hdr.rows - 1 - j) * image->hdr.cols;
  1498. X        Redk = Red + k;
  1499. X        if ((mode & COLOUR) != GREYSC)
  1500. X        {
  1501. X            Grnk = Grn + k; Bluk = Blu + k;
  1502. X        }
  1503. X        for (j=0; j<linewidth; j++)
  1504. X        {
  1505. X            get_pixel(&r,&g,&b,tga->PixelSize,mode);
  1506. X            *Redk++=r;
  1507. X            if ((mode & COLOUR) != GREYSC)
  1508. X            {
  1509. X                *Grnk++=g; *Bluk++=b;
  1510. X            }
  1511. X        }
  1512. X    }
  1513. X    free(tga);
  1514. X
  1515. X    return (1);
  1516. X}
  1517. X
  1518. X
  1519. Xget_map_entry(Red,Grn,Blu,Size,mode)
  1520. Xunsigned char     *Red,*Grn,*Blu;
  1521. Xint     Size,mode;
  1522. X{
  1523. Xunsigned int j,k,l;
  1524. Xunsigned char i,r,g,b;
  1525. X
  1526. X        /* read appropriate number of bytes, break into rgb & put in map */
  1527. X        switch (Size)
  1528. X        {
  1529. X            case 8: /* Grey Scale already, read and triplicate */
  1530. X                    fread(&i,1,1,stdin);
  1531. X            r = i; g = i; b = i;
  1532. X                    break;
  1533. X
  1534. X            case 16: /* 5 bits each of red green and blue */
  1535. X            case 15: /* Watch for byte order */
  1536. X                    fread(&j,1,1,stdin);
  1537. X                    fread(&k,1,1,stdin);
  1538. X                    l = j + k*256;
  1539. X                    r = ((l >> 10) & 31) << 3;
  1540. X                    g = ((l >>  5) & 31) << 3;
  1541. X                    b = (l & 31) << 3;
  1542. X                    break;
  1543. X
  1544. X            case 32: /* Read alpha byte & throw away */
  1545. X                    fread(&i,1,1,stdin);
  1546. X            case 24: /* Eight bits each of red green and blue */
  1547. X                    fread(&i,1,1,stdin); r = i;
  1548. X                    fread(&i,1,1,stdin); g = i;
  1549. X                    fread(&i,1,1,stdin); b = i;
  1550. X                    break;
  1551. X
  1552. X            default:
  1553. X                    fprintf(stderr,"Unknown Pixel Size\n"); exit(1);
  1554. X        }
  1555. X    *Red = r; *Grn = g; *Blu = b;
  1556. X}
  1557. X
  1558. Xget_pixel(rRed,rGrn,rBlu,Size,mode)
  1559. Xunsigned char *rRed,*rGrn,*rBlu;
  1560. Xint Size,mode;
  1561. X{
  1562. X    static unsigned char Red, Grn, Blu;
  1563. X    unsigned char i,j,k;
  1564. X    static unsigned int l;
  1565. X
  1566. X    /* Check if run length encoded. */
  1567. X    if ((mode & RLENCD) != 0)
  1568. X    {
  1569. X        if (RLE_count == 0) /* Have to restart run */
  1570. X        {
  1571. X            fread(&i,1,1,stdin);
  1572. X            RLE_flag = (i & 0x80) >> 7;
  1573. X            if (RLE_flag == 0)
  1574. X            { /* Stream of unencoded pixels */
  1575. X                RLE_count = i + 1;
  1576. X            }
  1577. X            else
  1578. X            { /* Single pixel replicated */
  1579. X                RLE_count = i - 127;
  1580. X            }
  1581. X            RLE_count--; /* Decrement count & get pixel */
  1582. X        }
  1583. X        else
  1584. X        { /* Have already read count & (at least) first pixel */
  1585. X            RLE_count--;
  1586. X            if (RLE_flag != 0)
  1587. X            { /* Replicated pixels */
  1588. X                goto PixEncode;
  1589. X            }
  1590. X        }
  1591. X    }
  1592. X    /* Read appropriate number of bytes, break into RGB */
  1593. X    switch(Size)
  1594. X    {
  1595. X    case 8: /* Grey Scale - read a byte and triplicate */
  1596. X        fread(&i,1,1,stdin);
  1597. X        Red = i; Grn = i; Blu = i; l = i;
  1598. X        break;
  1599. X
  1600. X    case 16: /* Five bits each of red green and blue */
  1601. X    case 15: /* Watch byte order */
  1602. X        fread(&j,1,1,stdin);
  1603. X        fread(&k,1,1,stdin);
  1604. X        l = j + k*256;
  1605. X        Red = ((k & 0x7C) << 1);
  1606. X        Grn = ((k & 0x03) << 6) + ((j & 0xE0) >> 2);
  1607. X        Blu = ((j & 0x1F) << 3);
  1608. X        break;
  1609. X
  1610. X    case 32: /* Read alpha byte & throw away */
  1611. X        fread(&i,1,1,stdin);
  1612. X    case 24: /* Eight bits each of red green and blue */
  1613. X        fread(&i,1,1,stdin); Red = i;
  1614. X        fread(&i,1,1,stdin); Grn = i;
  1615. X        fread(&i,1,1,stdin); Blu = i;
  1616. X        l = 0;
  1617. X        break;
  1618. X
  1619. X    default:
  1620. X        fprintf(stderr,"Unknown Pixel Size\n"); exit(1);
  1621. X    }
  1622. X
  1623. XPixEncode:
  1624. X    if ((mode & MAPPED) == MAPPED)
  1625. X    {
  1626. X        *rRed = ColourMap[l][0];
  1627. X        *rGrn = ColourMap[l][1];
  1628. X        *rBlu = ColourMap[l][2];
  1629. X    }
  1630. X    else
  1631. X    {
  1632. X        *rRed = Red;
  1633. X        *rGrn = Grn;
  1634. X        *rBlu = Blu;
  1635. X    }
  1636. X}
  1637. X
  1638. X/*
  1639. X * write_tga(image, wfile)
  1640. X *
  1641. X */
  1642. Xwrite_tga(image, wfile)
  1643. XFBM *image;
  1644. XFILE *wfile;
  1645. X{
  1646. Xunsigned char        *Red, *Grn, *Blu, *Redk, *Grnk, *Bluk;
  1647. Xunsigned char        *Redc, *Grnc, *Bluc, *Redck, *Grnck, *Bluck;
  1648. Xstruct TGA_ImageHeader    *tga;
  1649. Xunsigned char        buffer[MAXCOLOURS];
  1650. Xunsigned int        mode;
  1651. Xunsigned long        index, index2;
  1652. Xint            i, j, k, l;
  1653. X
  1654. X    if (image->hdr.cols > (MAXCOLOURS / 2))
  1655. X    {
  1656. X        fprintf(stderr,"Line too wide is %d, must be %d\n",
  1657. X        image->hdr.cols, MAXCOLOURS/2);
  1658. X        exit(1);
  1659. X    }
  1660. X
  1661. X    if ((image->hdr.planes != 1) && (image->hdr.planes != 3))
  1662. X    {
  1663. X        fprintf(stderr,"TGA files must 1 or 3 planes deep\n");
  1664. X        exit(1);
  1665. X    }
  1666. X    if (image->hdr.planes == 1) mode = GREYSC;
  1667. X    else mode = COLOUR;
  1668. X    
  1669. X    if ((tga=(struct TGA_ImageHeader *)
  1670. X             malloc(sizeof(struct TGA_ImageHeader))) == NULL)
  1671. X    {
  1672. X        fprintf(stderr,"Can't allocate TGA memory\n");
  1673. X        exit(1);
  1674. X    }
  1675. X    tga->IDLength = 0; /* Don't write ID into file */
  1676. X    tga->CoMapType = 0; /* Use raw bytes, not mapped */
  1677. X    
  1678. X    tga->ImgType = TGA_RawRGBType;
  1679. X    if ((mode & COLOUR) == GREYSC) tga->ImgType = TGA_RawMonoType;
  1680. X    
  1681. X    tga->Index_hi = 0; tga->Index_lo = 0; /* Colour Mapped stuff */
  1682. X    tga->Length_hi = 0; tga->Length_lo = 0;
  1683. X    tga->CoSize = 8;
  1684. X
  1685. X    tga->X_org_lo = 0; tga->X_org_hi = 0; /* Origin at 0,0 */
  1686. X    tga->Y_org_lo = 0; tga->Y_org_hi = 0;
  1687. X
  1688. X    tga->Width_hi = (unsigned char)(image->hdr.cols / 256);
  1689. X    tga->Width_lo = (unsigned char)(image->hdr.cols % 256);
  1690. X    tga->Height_hi = (unsigned char)(image->hdr.rows / 256);
  1691. X    tga->Height_lo = (unsigned char)(image->hdr.rows % 256);
  1692. X    
  1693. X    tga->PixelSize = 16;
  1694. X    if ((mode & COLOUR) == GREYSC) tga->PixelSize = 8;
  1695. X    
  1696. X    /* All funny bits set to zero */
  1697. X    tga->AttBits = 0; tga->Rsrvd = 0; tga->OrgBit; tga->IntrLve = 0;
  1698. X
  1699. X    fwrite(tga,1,18,wfile); /* Write out header */
  1700. X
  1701. X    Red = image->bm;
  1702. X    l = image->hdr.cols;
  1703. X    if ((mode & COLOUR) == COLOUR)
  1704. X    {
  1705. X        l = l * 2;
  1706. X        Grn = Red + image->hdr.plnlen;
  1707. X        Blu = Grn + image->hdr.plnlen;
  1708. X    }
  1709. X
  1710. X    if (image->hdr.clrlen > 0)
  1711. X    {
  1712. X        mode = mode | MAPPED;
  1713. X        Redc = image->cm;
  1714. X        if ((mode & COLOUR) == COLOUR)
  1715. X        {
  1716. X            Grnc = Redc + image->hdr.clrlen/3;
  1717. X            Bluc = Grnc + image->hdr.clrlen/3;
  1718. X        }
  1719. X    }
  1720. X    
  1721. X    Redk = Red + image->hdr.plnlen - image->hdr.cols;
  1722. X    if ((mode & COLOUR) == COLOUR)
  1723. X    {
  1724. X        Grnk = Grn + image->hdr.plnlen - image->hdr.cols;
  1725. X        Bluk = Blu + image->hdr.plnlen - image->hdr.cols;
  1726. X    }
  1727. X
  1728. X    /* Okay, ready to write */
  1729. X    for (j=0; j<image->hdr.rows; j++)
  1730. X    {
  1731. X    for (i=0; i<image->hdr.cols; i++)
  1732. X    {
  1733. X        index = *Redk++;
  1734. X        if ((mode & COLOUR) == COLOUR)
  1735. X            index = (index << 16) + ((*Grnk++) << 8) +  *Bluk++;
  1736. X
  1737. X        if ((mode & MAPPED) == MAPPED)
  1738. X        {
  1739. X            index2 = index;
  1740. X            Redck = Redc + index2;
  1741. X            index = *Redck;
  1742. X            if ((mode & COLOUR) == COLOUR)
  1743. X            {
  1744. X                Grnck = Grnc + index2; Bluck = Bluc + index2;
  1745. X                index = (index << 16) +
  1746. X                    ((unsigned long)*Grnck << 8) +
  1747. X                    *Bluck;
  1748. X            }
  1749. X        }
  1750. X        
  1751. X        if ((mode & COLOUR) == COLOUR)
  1752. X        {
  1753. X            index2 = ((index & 0x00f80000) >> 9)
  1754. X                   + ((index & 0x0000f800) >> 6)
  1755. X                   + ((index & 0x000000f8) >> 3);
  1756. X            k = 2 * i;
  1757. X            buffer[k] = (unsigned char)(index2 % 256);
  1758. X            k = k + 1;
  1759. X            buffer[k] = (unsigned char)(index2 / 256);
  1760. X        }
  1761. X        else
  1762. X        {
  1763. X            buffer[i] = (unsigned char)index;
  1764. X        }
  1765. X    }
  1766. X    fwrite(buffer,l,1,wfile);
  1767. X    Redk = Redk - 2 * image->hdr.cols;
  1768. X    if ((mode & COLOUR) == COLOUR)
  1769. X    {
  1770. X        Grnk = Grnk - 2 * image->hdr.cols;
  1771. X        Bluk = Bluk - 2 * image->hdr.cols;
  1772. X    }
  1773. X    }
  1774. X    free(tga);
  1775. X    
  1776. X    return (1);
  1777. X}
  1778. END_OF_FILE
  1779. if test 13220 -ne `wc -c <'fltga.c'`; then
  1780.     echo shar: \"'fltga.c'\" unpacked with wrong size!
  1781. fi
  1782. # end of 'fltga.c'
  1783. fi
  1784. echo shar: End of archive 6 \(of 8\).
  1785. cp /dev/null ark6isdone
  1786. MISSING=""
  1787. for I in 1 2 3 4 5 6 7 8 ; do
  1788.     if test ! -f ark${I}isdone ; then
  1789.     MISSING="${MISSING} ${I}"
  1790.     fi
  1791. done
  1792. if test "${MISSING}" = "" ; then
  1793.     echo You have unpacked all 8 archives.
  1794.     rm -f ark[1-9]isdone
  1795. else
  1796.     echo You still need to unpack the following archives:
  1797.     echo "        " ${MISSING}
  1798. fi
  1799. ##  End of shell archive.
  1800. exit 0
  1801.